dynamic class com.c3d.mediaRotator.transitions.PanelTransitionManager extends Object
{
    var _currentIndex: Number = 0;
    var _expiredIndex: Number = -1;
    var _isReady: Boolean = false;
    var _isStarted: Boolean = false;
    var _transitionType: String = "crossfade";
    var _mouseMoveTimeout: Number = 2000;
    static var _TRANSITION_IN_PROGRESS: Boolean = false;
    var _playbackPaused: Boolean = false;
    var _transitionInProgress: Boolean = false;
    var _activeTransitions;
    var _complexTransitionWrapper;
    var _controller;
    var _delay;
    var _duration;
    var _endTime;
    var _interactionTimeout;
    var _offTween;
    var _onTween;
    var _panelDisplayList;
    var _startTime;
    var _timerInterval;

    function PanelTransitionManager($panelDisplayList, $controller)
    {
        super();
        if (this._isReady) 
        {
            return;
        }
        this._controller = $controller;
        this._activeTransitions = new Array();
        this._complexTransitionWrapper = new Array();
        this._panelDisplayList = $panelDisplayList;
        var __reg3 = 0;
        while (__reg3 < this._panelDisplayList.length) 
        {
            if (__reg3 == this._currentIndex) 
            {
                this._panelDisplayList[__reg3]._alpha = 100;
            }
            else 
            {
                this._panelDisplayList[__reg3]._alpha = 0;
            }
            ++__reg3;
        }
        this._mouseMoveTimeout = this._controller.__get__transitionParameters().mouseMoveTimeout;
        this.attachEventListeners();
        this._isReady = true;
    }

    function attachEventListeners()
    {
        _root.onMouseMove = mx.utils.Delegate.create(this, this.onAMouseMove);
    }

    function requestTransitionToPanel($targetPanelClip)
    {
        if (this._transitionInProgress) 
        {
            return;
        }
        com.c3d.mediaRotator.transitions.PanelTransitionManager._TRANSITION_IN_PROGRESS = this._transitionInProgress = true;
        if (!this._playbackPaused) 
        {
            this.killMouseTimeout();
        }
        this.stop();
        var __reg3 = -1;
        var __reg2 = 0;
        while (__reg2 < this._panelDisplayList.length) 
        {
            if ($targetPanelClip == this._panelDisplayList[__reg2]) 
            {
                __reg3 = __reg2;
                break;
            }
            ++__reg2;
        }
        if (__reg3 == -1) 
        {
            com.c3d.mediaRotator.transitions.PanelTransitionManager._TRANSITION_IN_PROGRESS = this._transitionInProgress = false;
            return;
        }
        this.beginRequestedPanelTransiton(__reg3);
    }

    function beginRequestedPanelTransiton($targetID)
    {
        this.updateTimerParams();
        if ((__reg0 = this._transitionType) === "crossfade") 
        {
            var __reg2 = this._panelDisplayList[this._currentIndex];
            this._offTween = new mx.transitions.Tween(__reg2, "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, this._duration / 1000, true);
            this.seekToNewIndex($targetID);
            var __reg3 = this._panelDisplayList[this._currentIndex];
            this._onTween = new mx.transitions.Tween(__reg3, "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, this._duration / 1000, true);
            this._onTween.onMotionFinished = mx.utils.Delegate.create(this, this.onRequestedPanelTransitionComplete);
        }
        else 
        {
            __reg0 === "crossblur";
        }
        com.c3d.common.events.CentralDispatch.dispatchEvent({type: com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_REQUESTED_TRANSITION_BEGIN, target: null, newPanelIndex: this._currentIndex});
    }

    function onRequestedPanelTransitionComplete($event)
    {
        this.start();
        com.c3d.mediaRotator.transitions.PanelTransitionManager._TRANSITION_IN_PROGRESS = this._transitionInProgress = false;
        com.c3d.common.events.CentralDispatch.dispatchEvent({type: com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_REQUESTED_TRANSITION_COMPLETE, target: null, newPanelIndex: this._currentIndex});
    }

    function updateTimerParams()
    {
        this._delay = this._controller.__get__transitionParameters().delay;
        this._duration = this._controller.__get__transitionParameters().duration;
    }

    function onTimerTick()
    {
        if (this._transitionInProgress) 
        {
            return;
        }
        com.c3d.mediaRotator.transitions.PanelTransitionManager._TRANSITION_IN_PROGRESS = this._transitionInProgress = true;
        this.updateTimerParams();
        if ((__reg0 = this._transitionType) === "crossfade") 
        {
            var __reg2 = this._panelDisplayList[this._currentIndex];
            this._offTween = new mx.transitions.Tween(__reg2, "_alpha", mx.transitions.easing.Strong.easeOut, 100, 0, this._duration / 1000, true);
            this.moveToNextIndex();
            var __reg3 = this._panelDisplayList[this._currentIndex];
            this._onTween = new mx.transitions.Tween(__reg3, "_alpha", mx.transitions.easing.Strong.easeOut, 0, 100, this._duration / 1000, true);
            this._onTween.onMotionFinished = mx.utils.Delegate.create(this, this.onPanelTransitionComplete);
        }
        else 
        {
            __reg0 === "crossblur";
        }
        com.c3d.common.events.CentralDispatch.dispatchEvent({type: com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_TRANSITION_BEGIN, target: null, newPanelIndex: this._currentIndex});
    }

    function onPanelTransitionComplete()
    {
        com.c3d.mediaRotator.transitions.PanelTransitionManager._TRANSITION_IN_PROGRESS = this._transitionInProgress = false;
        this.start();
        com.c3d.common.events.CentralDispatch.dispatchEvent({type: com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_TRANSITION_COMPLETE, target: null, newPanelIndex: this._currentIndex});
    }

    function snapBitmap($snapSource, $snapTarget)
    {
        var __reg1 = new flash.display.BitmapData($snapSource._width, $snapSource._height, true);
        __reg1.draw($snapSource);
        $snapTarget.attachBitmap(__reg1, $snapTarget.getNextHighestDepth());
    }

    function moveToNextIndex()
    {
        this._expiredIndex = this._currentIndex;
        ++this._currentIndex;
        if (this._currentIndex >= this._panelDisplayList.length) 
        {
            this._currentIndex = 0;
        }
    }

    function moveToPrevIndex()
    {
        this._expiredIndex = this._currentIndex;
        --this._currentIndex;
        if (this._currentIndex < 0) 
        {
            this._currentIndex = this._panelDisplayList.length - 1;
        }
    }

    function seekToNewIndex($newIndex)
    {
        this._expiredIndex = this._currentIndex;
        if ($newIndex >= 0 && $newIndex < this._panelDisplayList.length) 
        {
            this._currentIndex = $newIndex;
        }
    }

    function start()
    {
        this.updateTimerParams();
        var __reg2 = Number(this._delay) + Number(this._duration);
        if (this._isStarted) 
        {
            if (this._playbackPaused == true) 
            {
                __reg2 = __reg2 - (getTimer() - this._startTime);
                this._playbackPaused = false;
                clearTimeout(this._timerInterval);
                this._timerInterval = setTimeout(mx.utils.Delegate.create(this, this.onTimerTick), __reg2);
            }
            else 
            {
                clearTimeout(this._timerInterval);
                this._timerInterval = setTimeout(mx.utils.Delegate.create(this, this.onTimerTick), __reg2);
                com.c3d.common.events.CentralDispatch.dispatchEvent({type: com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_STARTUP_REQUEST, target: this});
            }
        }
        else if (this._playbackPaused == true) 
        {
            this._playbackPaused = false;
            clearInterval(this._timerInterval);
            this._timerInterval = setTimeout(mx.utils.Delegate.create(this, this.onTimerTick), __reg2);
            this.updateTimerParams();
            com.c3d.common.events.CentralDispatch.dispatchEvent({type: com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_STARTUP_REQUEST, target: this});
            this._isStarted = true;
        }
        else 
        {
            clearTimeout(this._timerInterval);
            this._timerInterval = setTimeout(mx.utils.Delegate.create(this, this.onTimerTick), __reg2);
            this.updateTimerParams();
            com.c3d.common.events.CentralDispatch.dispatchEvent({type: com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_STARTUP_REQUEST, target: this, initParams: {delay: this._delay / 1000, duration: this._duration / 1000}});
            this._isStarted = true;
        }
        this._startTime = getTimer();
    }

    function interactionTriggeredStart()
    {
        this.updateTimerParams();
        var __reg3 = Number(this._delay) + Number(this._duration);
        if (this._playbackPaused == true) 
        {
            this._playbackPaused = false;
            var __reg2 = __reg3 - (this._endTime - this._startTime);
            this._timerInterval = setTimeout(mx.utils.Delegate.create(this, this.onTimerTick), __reg2);
            this.updateTimerParams();
            com.c3d.common.events.CentralDispatch.dispatchEvent({type: com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_STARTUP_REQUEST_INTERACTION, target: this, initParams: {delay: __reg2, duration: this._duration / 1000}});
            this._isStarted = true;
        }
        this._startTime = getTimer();
    }

    function stop()
    {
        clearTimeout(this._timerInterval);
        this._isStarted = false;
        com.c3d.common.events.CentralDispatch.dispatchEvent({type: com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_HALT_REQUEST, target: this});
    }

    function interactionTriggeredStop()
    {
        clearTimeout(this._timerInterval);
        this._isStarted = false;
        com.c3d.common.events.CentralDispatch.dispatchEvent({type: com.c3d.mediaRotator.events.PanelTransitionEvent.TRANSITION_CONTROLLER_HALT_REQUEST_INTERACTION, target: this});
    }

    function pausePlayback()
    {
        this._playbackPaused = true;
        this._endTime = getTimer();
        clearTimeout(this._interactionTimeout);
        this.interactionTriggeredStop();
    }

    function resumePlayback()
    {
        this.interactionTriggeredStart();
    }

    function resetPlayback()
    {
    }

    function set delay($n)
    {
    }

    function set panelList($ar)
    {
    }

    function get currentPanel()
    {
        return this._panelDisplayList[this._currentIndex];
    }

    function get isReady()
    {
        return this._isReady;
    }

    function onAMouseMove()
    {
        if (!this._controller.__get__modalOverlayVisible() && this._isStarted == true) 
        {
            if (!this._playbackPaused) 
            {
                this.pausePlayback();
            }
            clearTimeout(this._interactionTimeout);
            this._interactionTimeout = setTimeout(mx.utils.Delegate.create(this, this.onMouseTimeout), this._mouseMoveTimeout);
        }
    }

    function killMouseTimeout()
    {
        clearTimeout(this._interactionTimeout);
        this._playbackPaused = false;
        this.resumePlayback();
    }

    function onMouseTimeout()
    {
        if (this._controller.__get__modalOverlayVisible()) 
        {
            return;
        }
        this.resumePlayback();
    }

    static function get TRANSITION_IN_PROGRESS()
    {
        return com.c3d.mediaRotator.transitions.PanelTransitionManager._TRANSITION_IN_PROGRESS;
    }

}
